import { request, apiUrl } from '@/api/request';
/**
 * 说明 : 调用此接口 , 可获取 APP 首页信息
 * 可选参数 :
 * refresh: 是否刷新数据,默认为 false
 * cursor: 上一条数据返回的 cursor
 */
// type HomePage = {
//   refresh?: boolean;
//   cursor?: string | number | null;
// };
export function getHomePageBlockPage(params) {
  return request(apiUrl.HOMEPAGE_BLOCK_PAGE, params).then(res => {
    const blocks = res.data.blocks;
    console.log('blocks: ', blocks);
    return formatHomeBlocks(blocks);
  });
}

export function formatHomeBlocks(blocks) {
  // HOMEPAGE_BANNER;
  const HOMEPAGE_BANNER = blocks.find(item => item.blockCode == 'HOMEPAGE_BANNER');
  // HOMEPAGE_BLOCK_PLAYLIST_RCMD;
  const HOMEPAGE_BLOCK_PLAYLIST_RCMD = blocks.find(item => item.blockCode == 'HOMEPAGE_BLOCK_PLAYLIST_RCMD');
  // HOMEPAGE_BLOCK_STYLE_RCMD;
  const HOMEPAGE_BLOCK_STYLE_RCMD = blocks.find(item => item.blockCode == 'HOMEPAGE_BLOCK_STYLE_RCMD');
  // HOMEPAGE_BLOCK_NEW_ALBUM_NEW_SONG;
  const HOMEPAGE_BLOCK_NEW_ALBUM_NEW_SONG = blocks.find(item => item.blockCode == 'HOMEPAGE_BLOCK_NEW_ALBUM_NEW_SONG');
  // HOMEPAGE_BLOCK_HOT_TOPIC
  const HOMEPAGE_BLOCK_HOT_TOPIC = blocks.find(item => item.blockCode == 'HOMEPAGE_BLOCK_HOT_TOPIC');
  // HOMEPAGE_MUSIC_CALENDAR;
  const HOMEPAGE_MUSIC_CALENDAR = blocks.find(item => item.blockCode == 'HOMEPAGE_MUSIC_CALENDAR');
  // HOMEPAGE_MUSIC_MLOG;
  const HOMEPAGE_MUSIC_MLOG = blocks.find(item => item.blockCode == 'HOMEPAGE_MUSIC_MLOG');
  // HOMEPAGE_BLOCK_MGC_PLAYLIST;
  const HOMEPAGE_BLOCK_MGC_PLAYLIST = blocks.find(item => item.blockCode == 'HOMEPAGE_BLOCK_MGC_PLAYLIST');
  // HOMEPAGE_BLOCK_OFFICIAL_PLAYLIST;
  const HOMEPAGE_BLOCK_OFFICIAL_PLAYLIST = blocks.find(item => item.blockCode == 'HOMEPAGE_BLOCK_OFFICIAL_PLAYLIST');
  // HOMEPAGE_VOICELIST_RCMD;
  const HOMEPAGE_VOICELIST_RCMD = blocks.find(item => item.blockCode == 'HOMEPAGE_VOICELIST_RCMD');
  // HOMEPAGE_BLOCK_YUNCUN_PRODUCED
  const HOMEPAGE_BLOCK_YUNCUN_PRODUCED = blocks.find(item => item.blockCode == 'HOMEPAGE_BLOCK_YUNCUN_PRODUCED');
  // HOMEPAGE_PODCAST24;
  const HOMEPAGE_PODCAST24 = blocks.find(item => item.blockCode == 'HOMEPAGE_PODCAST24');
  // HOMEPAGE_BLOCK_VIDEO_PLAYLIST;
  const HOMEPAGE_BLOCK_VIDEO_PLAYLIST = blocks.find(item => item.blockCode == 'HOMEPAGE_BLOCK_VIDEO_PLAYLIST');
  return {
    HOMEPAGE_BANNER,
    HOMEPAGE_BLOCK_PLAYLIST_RCMD,
    HOMEPAGE_BLOCK_STYLE_RCMD,
    HOMEPAGE_BLOCK_NEW_ALBUM_NEW_SONG,
    HOMEPAGE_BLOCK_HOT_TOPIC,
    HOMEPAGE_MUSIC_CALENDAR,
    HOMEPAGE_MUSIC_MLOG,
    HOMEPAGE_BLOCK_MGC_PLAYLIST,
    HOMEPAGE_BLOCK_OFFICIAL_PLAYLIST,
    HOMEPAGE_VOICELIST_RCMD,
    HOMEPAGE_BLOCK_YUNCUN_PRODUCED,
    HOMEPAGE_PODCAST24,
    HOMEPAGE_BLOCK_VIDEO_PLAYLIST
  };
}

/**
 * 说明 : 调用此接口 , 可获取 APP 首页圆形图标入口列表
 */
export function getHomePageDragonBall() {
  return request(apiUrl.HOMEPAGE_DRAGON_BALL);
}
/**
 * 首页包括的信息
HOMEPAGE_BANNER
HOMEPAGE_BLOCK_PLAYLIST_RCMD
HOMEPAGE_BLOCK_STYLE_RCMD
HOMEPAGE_BLOCK_NEW_ALBUM_NEW_SONG
HOMEPAGE_BLOCK_HOT_TOPIC
HOMEPAGE_MUSIC_CALENDAR
HOMEPAGE_MUSIC_MLOG
HOMEPAGE_BLOCK_MGC_PLAYLIST
HOMEPAGE_BLOCK_OFFICIAL_PLAYLIST
HOMEPAGE_VOICELIST_RCMD
HOMEPAGE_BLOCK_YUNCUN_PRODUCED
HOMEPAGE_PODCAST24
HOMEPAGE_BLOCK_VIDEO_PLAYLIST
*/
